{include file='header'/}
<style>
    .layui-breadcrumb {visibility: visible;}
</style>

<body>
<div class="weadmin-nav">
			<span class="layui-breadcrumb">
       		 <a href="">首页</a><span lay-separator="">/</span>
        	<a href="">常规管理</a><span lay-separator="">/</span>
            <a><cite>附件管理</cite></a>
      </span>
    <a class="layui-btn layui-btn-sm" style="float:right;margin-top: 5px" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon">&#xe9aa;</i></a>
</div>
<div class="weadmin-body">
    <blockquote class="layui-elem-quote">
        主要用于管理上传到服务器或第三方存储的数据
    </blockquote>
    <div class="layui-row demoTable" style="margin: 5px auto 15px">
        <form class="layui-form layui-col-md12" action="javascript:;" id="form_admin_search">
            搜索：
            <div class="layui-inline">
                <input type="text" name="picName" id="picName" placeholder="请输入图片名" autocomplete="off" class="layui-input">
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">时间范围</label>
                <div class="layui-input-inline">
                    <input type="text" class="layui-input" name="createtime" id="createtime" placeholder=" - ">
                </div>
            </div>
            <button class="layui-btn" data-type="reload" lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i>搜索</button>
            <button class="layui-btn layui-btn-danger" type="reset"><i class="layui-icon">&#xe63f;</i>清空</button>
        </form>
    </div>
    <div class="weadmin-block">
        <button class="layui-btn" id="test1" ><i class="layui-icon"></i>上传</button>
        <span class="fr" style="line-height:40px;padding-right: 10px;">共有数据：<span  id="total"></span> 条</span>
    </div>
    <table id="role_list" lay-filter="role_list"></table>
</div>
<script type="text/html" id="barDemo">
    {{#  if(d.storage =='local'){ }}
        {if(check_auth('general.attachment/delete'))}
        <a class="layui-btn layui-btn-danger layui-btn-sm" lay-event="del">删除</a>
        {/if}
    {{#  } else { }}
    <a class="layui-btn layui-btn-danger layui-btn-sm layui-btn-disabled">删除</a>
    {{#  } }}

</script>
<script type="text/html" id="view_img">
    {{#  if(d.url !='' && d.is_file==1){ }}
    <img src="{{d.url}}" onmouseover="hui_img_preview('logo2','{{d.url}}')" onmouseout="layer.closeAll();" id="logo2" width="30" >
    {{#  } else { }}
    <span class="we-red">不存在</span>
    {{#  } }}
</script>
<script type="text/html" id="urlurl">
    <a href="{{d.url}}" target="_blank">{{d.url}}</a>
</script>

{include file='footer'/}
<script>
    layui.use(['laydate','table','form','upload'], function(){
        var table = layui.table,laydate = layui.laydate,form = layui.form, upload = layui.upload;
        form.render();
        laydate.render({
            elem: '#createtime'
            ,range: true
            ,max:"{php}echo date('Y-m-d',time()){/php}"
        });
        //普通图片上传
        var uploadInst = upload.render({
            elem: '#test1'
            , url: "{:url('upload/index')}"
            ,field:"Filedata"
            ,done: function(res){
                console.log(res.src)
                if(res.status==1){
                    ptable.reload();
                }
            }
        })
        //第一个实例
        ptable = table.render({
            elem: '#role_list'
            ,page: false
            ,where:{do:1}
            ,method: 'get'
            ,url: '{:url('index')}' //数据接口
            ,done: function(res){ //res 即为原始返回的数据
                $("#total").html(res.count);
            }
            ,cols: [[ //表头
                {field: 'id', title: 'ID', width:90,align:'center'}
                ,{field: 'view_img', title: '预览',width:100,templet:'#view_img',align:'center'}
                ,{field: 'url', title: '物理路径',templet:'#urlurl'}
                ,{field: 'imagewidth', title: '宽度',width:70,align:'center'}
                ,{field: 'imageheight', title: '高度',width:70,align:'center'}
                ,{field: 'imagetype', title: '图片类型',width:100,align:'center'}
                ,{field: 'storage', title: '存储引擎',width:100,align:'center'}
                ,{field: 'filesize', title: '文件大小',width:150,align:'center'}
                ,{field: 'mimetype', title: 'Mime类型',width:130,align:'center'}
                ,{field: 'createtime', title: '创建时间',width:220,align:'center'}
                ,{fixed: 'right', title:'操作', toolbar: '#barDemo',align:'center',width:150}
            ]]
            ,id: 'testReload'
            ,page:true
            ,limit:10
        });
        var $ = layui.$, active = {
            reload: function() {
                //执行重载
                table.reload('testReload', {
                    page: {curr: 1},
                    where: {
                        key: {
                            picName: $('#picName').val(),
                            createtime: $('#createtime').val(),
                        }
                    }
                });
            },
        };
        $('.demoTable .layui-btn').on('click', function() {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        //监听行工具事件
        table.on('tool(role_list)', function(obj){
            var data = obj.data;
            if(obj.event === 'del'){
                layer.confirm('你确定要删除吗？', {
                    btn: ['确定','取消'] //按钮
                }, function(){
                    var postdata ={ids :data.id};
                    posttips("{:url('delete')}",postdata);
                });
            } else if(obj.event === 'detail'){
                WeAdminShow("查看详情","{:url('detail')}?id="+data.id,'850','550');
            }
        });
    });
</script>
</body>
</html>